package com.example.graalvm21.config.db;

/**
 * <p>自动获取当前线程对于的数据源</p>
 *
 * @author wz
 *
 * @date 2025/10/27 9:29
 *
 * @version 1.0
 */
public class DbContextHolder {
    private static final ThreadLocal<Object> CONTEXT_HOLDER = new ThreadLocal<>();

    /**
     * @title 设置数据源
     *
     * @author wz
     */
    public static void setDbType(DBTypeEnum dbTypeEnum) {
        CONTEXT_HOLDER.set(dbTypeEnum.getValue());
    }

    /**
     * @title 取得当前数据源
     *
     * @author wz
     */
    public static String getDbType() {
        return (String) CONTEXT_HOLDER.get();
    }

    /**
     * @title 清除上下文数据
     *
     * @author wz
     */
    public static void clearDbType() {
        CONTEXT_HOLDER.remove();
    }
}
